#ifndef HandController_H
#define HandController_H

#include <qmainwindow.h>
#include <baseclient.h>
#include <basedevice.h>
#include <indicom.h>
#include <qsettings.h>

#include "MountDisplay.h"
#include "Pad.h"
#include "HCSettings.h"

namespace Ui
{
class HandController;
class MountDisplay;
class Pad;
class HCSettings;
}

/*typedef struct coord {
  double ra;
  double dec;
} coord_t;
*/

class HandController: public QMainWindow, public INDI::BaseClient {
  Q_OBJECT

signals:
  void equatorialchanged(double ra, double dec);
  void horizontalchanged(double alt, double az);
  void lstchanged(double lst);
  void utcchanged(QString);
  void serverstatus(bool status);
  void mountconnected(INDI::BaseDevice *);
  void observerchanged(double lng, double lat);
  void speedindexchanged(int);
  void newgoto(double ra, double dec);
  
  void serverconnected();
  void serverdisconnected(int);
  
public slots:
  bool connectServer();
  bool disconnectServer();
  void changeServerStatus(bool status);
  void changeMountStatus(INDI::BaseDevice *);
  void changeObserver(double lng, double lat); 
  void changeUTC(QString);
  void addGoto(double, double);
  void marklastGotoasSynced(double, double);
  
public:
  HandController(QWidget *parent=0);
  QString getServerName();
  QString getPortString();
  QString getMountName();
  void setServerName(QString s);
  void setPortString(QString s);
  void setMountName(QString s);
  
protected:
  virtual void newDevice(INDI::BaseDevice *dp);
  virtual void newProperty(INDI::Property *property);
  virtual void removeProperty(INDI::Property *property);
  virtual void newBLOB(IBLOB *bp);
  virtual void newSwitch(ISwitchVectorProperty *svp);
  virtual void newNumber(INumberVectorProperty *nvp);
  virtual void newMessage(INDI::BaseDevice *dp, int messageID);
  virtual void newText(ITextVectorProperty *tvp);
  virtual void newLight(ILightVectorProperty *lvp);
  virtual void serverConnected();
  virtual void serverDisconnected(int exit_code);  
  
  void initSettings();
  void initInfo();
  virtual void closeEvent(QCloseEvent *event);
protected:
  Ui::HandController *ui;
  MountDisplay *mountdisplay;
  Pad *pad;
  QSettings *settings;
  HCSettings *hcsettings;
  
private:
  QString server, port, mountname;
  INDI::BaseDevice *mountdevice;
  bool mountwasconnected;
  double obs_lon, obs_lat, obs_lst;
  QString obs_utc;
  double currentRA, currentDEC, currentAlt, currentAz;
  bool isGoto, inGoto;
  QList<coord_t> gotos;

};

#endif // HandController_H